#include <bits/stdc++.h>
#define re register
#define chmin(a,b) (a = min(a,b))

using namespace std;

const int N = 5e4 + 10;
const int inf = 1e9 + 10;
int n,m;
int r,dp[2][N];
int nxt[N],fail[N][30];
char s[N],t[N];

inline int read(){
    int r = 0,w = 1;
    char c = getchar();
    while (c < '0' || c > '9'){
        if (c == '-') w = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9'){
        r = (r << 3) + (r << 1) + (c ^ 48);
        c = getchar();
    }
    return r * w;
}

int main(){
    freopen("neck.in","r",stdin);
    freopen("neck.out","w",stdout);
    scanf("%s%s",s + 1,t + 1);
    n = strlen(s + 1),m = strlen(t + 1);
    fill(dp[0] + 1,dp[0] + m + 1,inf);
    for (re int i = 0,j = 0;i < m;i++){
        if (i >= 1){
            j = fail[j][t[i + 1] - 'a'];
            if (t[i + 1] == t[j + 1]) j++;
            nxt[i + 1] = j;
        }
        for (re int k = 0;k < 26;k++){
            if (t[i + 1] - 'a' == k) fail[i][k] = i;
            else fail[i][k] = fail[nxt[i]][k];
            // if (fail[i][k]) cerr << i << " " << (char)(k + 'a') << " " << fail[i][k] << " ???\n";
        }
    }
    for (re int i = 0;i < m;i++){
        for (re int j = 0;j < 26;j++){
            if (t[fail[i][j] + 1] == j + 'a') fail[i][j]++;
        }
    }
    for (re int i = 1;i <= n;i++){
        r ^= 1;
        // for (re int j = 0;j <= m;j++) dp[r][j] = inf;
        for (re int j = 0;j < m;j++) dp[r][j] = dp[r ^ 1][j] + 1;
        for (re int j = 0;j < m;j++){
            if (s[i] == t[j + 1]){
                if (j + 1 < m) chmin(dp[r][j + 1],dp[r ^ 1][j]);
            }
            else chmin(dp[r][fail[j][s[i] - 'a']],dp[r ^ 1][j]);
        }
        // for (re int j = 0;j < m;j++) cerr << i << " " << j << " " << dp[r][j] << " ???\n";
    } printf("%d",n - *min_element(dp[r],dp[r] + m));
    return 0;
}